// Frontend
// $Id: Frontend.java,v 1.39 2003/07/20 06:46:17 axelwernicke Exp $
//
// Copyright (C) 2002-2003 Axel Wernicke <axel.wernicke@gmx.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

package de.axelwernicke.mypod.gui;

import java.awt.Component;
import java.awt.Cursor;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JMenu;

import de.axelwernicke.mypod.AutoPlaylist;
import de.axelwernicke.mypod.Playlist;
import de.axelwernicke.mypod.Preferences;
import de.axelwernicke.mypod.myPod;
import de.axelwernicke.mypod.util.ClipsTableUtils;


/**
 * This class contains all the gui stuff for the main window.
 * Please note, that most of the event & action handling is done
 * in de.axelwernicke.mypod.myPod.
 *
 * @author  axel wernicke
 */
public class Frontend extends javax.swing.JFrame {
    /** jdk1.4 logger */
//  private static Logger logger = Logger.getLogger("de.axelwernicke.mypod.gui");
    boolean locked = false;

    /** Creates new form Frontend */
    public Frontend() {
        initComponents();

        // set myPod icon for main window title and tasklist
        this.setIconImage(new javax.swing.ImageIcon(getClass().getResource("/resource/myPodIcon.jpg")).getImage());

        // add selection changes listener for the clips table
        this.clipsTableView.getSelectionModel().addListSelectionListener(new javax.swing.event.ListSelectionListener() {
                public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                    clipsListViewValueChanged(evt);
                }
            });
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() //GEN-BEGIN:initComponents
     {
        playlistPopupMenu = new javax.swing.JPopupMenu();
        playPopupItem = new javax.swing.JMenuItem();
        playAppendPopupItem = new javax.swing.JMenuItem();
        jSeparator3 = new javax.swing.JSeparator();
        syncIPodCheckBoxMenuItem = new javax.swing.JCheckBoxMenuItem();
        renamePlaylistPopupItem = new javax.swing.JMenuItem();
        deletePlaylistPopupItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JSeparator();
        updateAutoplaylistPpupItem = new javax.swing.JMenuItem();
        jSeparator11 = new javax.swing.JSeparator();
        propertyPlaylistPopupItem = new javax.swing.JMenuItem();
        clipPopupMenu = new javax.swing.JPopupMenu();
        playPopupItem1 = new javax.swing.JMenuItem();
        playAppendPopupItem1 = new javax.swing.JMenuItem();
        jSeparator4 = new javax.swing.JSeparator();
        addPlaylistMenu = new javax.swing.JMenu();
        jSeparator5 = new javax.swing.JSeparator();
        removeFromPlaylsitPopupItem = new javax.swing.JMenuItem();
        removeFromMyPodPopupItem = new javax.swing.JMenuItem();
        deletePopupItem = new javax.swing.JMenuItem();
        jSeparator6 = new javax.swing.JSeparator();
        clipPropertiesPopupItem = new javax.swing.JMenuItem();
        toolbarPanel = new javax.swing.JPanel();
        myPodToolBar = new javax.swing.JToolBar();
        scanButton = new javax.swing.JButton();
        preferencesButton = new javax.swing.JButton();
        playlistToolBar = new javax.swing.JToolBar();
        addPlaylistButton = new javax.swing.JButton();
        addAutoPlaylistButton = new javax.swing.JButton();
        deletePlaylistButton = new javax.swing.JButton();
        iPodToolBar = new javax.swing.JToolBar();
        synchronizeIPodButton = new javax.swing.JButton();
        wipeIPodButton = new javax.swing.JButton();
        splitPane = new javax.swing.JSplitPane();
        playlistScrollPane = new javax.swing.JScrollPane();
        playlistListView = new de.axelwernicke.mypod.gui.PlaylistListView();
        viewContainer = new javax.swing.JTabbedPane();
        fullListScrollPane = new javax.swing.JScrollPane();
        clipsTableView = new de.axelwernicke.mypod.gui.ListView();
        artistViewSplitPane = new javax.swing.JSplitPane();
        artistSpreaderScrollPane = new javax.swing.JScrollPane();
        spreaderListView = new javax.swing.JList();
        artistListScrollPane = new javax.swing.JScrollPane();
        albumViewSplitPane = new javax.swing.JSplitPane();
        albumSpreaderScrollPane = new javax.swing.JScrollPane();
        albumListScrollPane = new javax.swing.JScrollPane();
        genreViewSplitPane = new javax.swing.JSplitPane();
        genreSpreaderScrollPane = new javax.swing.JScrollPane();
        genreListScrollPane = new javax.swing.JScrollPane();
        statusLine = new javax.swing.JPanel();
        clipsInfoLabel = new javax.swing.JLabel();
        dummyjPanel = new javax.swing.JPanel();
        menuBar = new javax.swing.JMenuBar();
        fileMenu = new javax.swing.JMenu();
        scanMenuItem = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JSeparator();
        preferencesMenuItem = new javax.swing.JMenuItem();
        separator = new javax.swing.JSeparator();
        exitMenuItem = new javax.swing.JMenuItem();
        playlistMenu = new javax.swing.JMenu();
        playMenuItem = new javax.swing.JMenuItem();
        playAppendMenuItem = new javax.swing.JMenuItem();
        jSeparator12 = new javax.swing.JSeparator();
        newPlaylistMenuItem = new javax.swing.JMenuItem();
        newAutoPlaylistMenuItem = new javax.swing.JMenuItem();
        renamePlaylistMenuItem = new javax.swing.JMenuItem();
        deletePlaylistMenuItem = new javax.swing.JMenuItem();
        jSeparator31 = new javax.swing.JSeparator();
        importPlaylistMenuItem = new javax.swing.JMenuItem();
        exportPlaylistMenuItem = new javax.swing.JMenuItem();
        updateAutoplaylistMenuItem = new javax.swing.JMenuItem();
        jSeparator111 = new javax.swing.JSeparator();
        propertyPlaylistMenuItem = new javax.swing.JMenuItem();
        clipMenu = new javax.swing.JMenu();
        playPopupItem2 = new javax.swing.JMenuItem();
        playAppendPopupItem2 = new javax.swing.JMenuItem();
        jSeparator8 = new javax.swing.JSeparator();
        removeClipsPlaylistMenuItem = new javax.swing.JMenuItem();
        removeClipsMyPodMenuItem = new javax.swing.JMenuItem();
        deleteClipsMenuItem = new javax.swing.JMenuItem();
        jSeparator7 = new javax.swing.JSeparator();
        clipPropertiesMenuItem = new javax.swing.JMenuItem();
        iPodMenu = new javax.swing.JMenu();
        synchronizeIPodMenuItem = new javax.swing.JMenuItem();
        wipeIPodMenuItem = new javax.swing.JMenuItem();
        ToolsMenu = new javax.swing.JMenu();
        removeMissingClipsMenuItem = new javax.swing.JMenuItem();
        relocateMissingClipsMenuItem = new javax.swing.JMenuItem();
        reorganizeClipsMenuItem = new javax.swing.JMenuItem();
        helpMenu = new javax.swing.JMenu();
        helpMenuItem = new javax.swing.JMenuItem();
        aboutMenuItem = new javax.swing.JMenuItem();

        playlistPopupMenu.setName("playlistPopupMenu");
        playPopupItem.setAction(myPod.getPlayPlaylistAddAction(myPod.POPUP_ACTION));
        playPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        playlistPopupMenu.add(playPopupItem);

        playAppendPopupItem.setAction(myPod.getPlayPlaylistAppendAction(myPod.POPUP_ACTION));
        playAppendPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        playlistPopupMenu.add(playAppendPopupItem);

        playlistPopupMenu.add(jSeparator3);

        syncIPodCheckBoxMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        syncIPodCheckBoxMenuItem.setAction(myPod.getSetIPodSyncAction(myPod.POPUP_ACTION));
        playlistPopupMenu.add(syncIPodCheckBoxMenuItem);

        renamePlaylistPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        renamePlaylistPopupItem.setAction(myPod.getRenamePlaylistAction(myPod.POPUP_ACTION));
        playlistPopupMenu.add(renamePlaylistPopupItem);

        deletePlaylistPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        deletePlaylistPopupItem.setAction(myPod.getDeletePlaylistAction(myPod.POPUP_ACTION));
        playlistPopupMenu.add(deletePlaylistPopupItem);

        playlistPopupMenu.add(jSeparator1);

        updateAutoplaylistPpupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        updateAutoplaylistPpupItem.setAction(myPod.getUpdateAutoPlaylistAction(myPod.POPUP_ACTION));
        playlistPopupMenu.add(updateAutoplaylistPpupItem);

        playlistPopupMenu.add(jSeparator11);

        propertyPlaylistPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        propertyPlaylistPopupItem.setAction(myPod.getPlaylistPropertyAction(myPod.POPUP_ACTION));
        playlistPopupMenu.add(propertyPlaylistPopupItem);

        clipPopupMenu.setName("clipPopupMenu");
        playPopupItem1.setAction(myPod.getPlayClipsAddAction(myPod.POPUP_ACTION));
        playPopupItem1.setFont(new java.awt.Font("Dialog", 1, 10));
        clipPopupMenu.add(playPopupItem1);

        playAppendPopupItem1.setAction(myPod.getPlayClipsAppendAction(myPod.POPUP_ACTION));
        playAppendPopupItem1.setFont(new java.awt.Font("Dialog", 1, 10));
        clipPopupMenu.add(playAppendPopupItem1);

        clipPopupMenu.add(jSeparator4);

        addPlaylistMenu.setText(GuiUtils.getStringLocalized("resource/language", "addToPlaylist..."));
        addPlaylistMenu.setFont(new java.awt.Font("Dialog", 1, 10));
        addPlaylistMenu.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Dummy16.gif")));
        clipPopupMenu.add(addPlaylistMenu);

        clipPopupMenu.add(jSeparator5);

        removeFromPlaylsitPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        removeFromPlaylsitPopupItem.setAction(myPod.getRemoveClipsPlaylistAction(myPod.POPUP_ACTION));
        clipPopupMenu.add(removeFromPlaylsitPopupItem);

        removeFromMyPodPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        removeFromMyPodPopupItem.setAction(myPod.getRemoveClipsMyPodAction(myPod.POPUP_ACTION));
        clipPopupMenu.add(removeFromMyPodPopupItem);

        deletePopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        deletePopupItem.setAction(myPod.getDeleteClipsAction(myPod.POPUP_ACTION));
        clipPopupMenu.add(deletePopupItem);

        clipPopupMenu.add(jSeparator6);

        clipPropertiesPopupItem.setFont(new java.awt.Font("Dialog", 1, 10));
        clipPropertiesPopupItem.setAction(myPod.getClipPropertiesAction(myPod.POPUP_ACTION));
        clipPopupMenu.add(clipPropertiesPopupItem);

        setTitle(GuiUtils.getStringLocalized("resource/language", "myPod"));
        addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    formWindowClosing(evt);
                }
            });

        toolbarPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0));

        myPodToolBar.setRollover(true);
        scanButton.setAction(myPod.getScanAction(myPod.TOOLBAR_ACTION));
        scanButton.setFont(new java.awt.Font("Dialog", 1, 10));
        scanButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Eject24.gif")));
        scanButton.setText(GuiUtils.getStringLocalized("dummy"));
        scanButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        scanButton.setRolloverEnabled(true);
        myPodToolBar.add(scanButton);

        preferencesButton.setAction(myPod.getPreferencesAction(myPod.TOOLBAR_ACTION));
        preferencesButton.setFont(new java.awt.Font("Dialog", 1, 10));
        preferencesButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/Preferences24.gif")));
        preferencesButton.setText(GuiUtils.getStringLocalized("dummy"));
        preferencesButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        preferencesButton.setRolloverEnabled(true);
        myPodToolBar.add(preferencesButton);

        toolbarPanel.add(myPodToolBar);

        playlistToolBar.setRollover(true);
        addPlaylistButton.setAction(myPod.getNewPlaylistAction(myPod.TOOLBAR_ACTION));
        addPlaylistButton.setFont(new java.awt.Font("Dialog", 1, 10));
        addPlaylistButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/New24.gif")));
        addPlaylistButton.setText(GuiUtils.getStringLocalized("dummy"));
        addPlaylistButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        addPlaylistButton.setName("addPlaylistButton");
        playlistToolBar.add(addPlaylistButton);

        addAutoPlaylistButton.setAction(myPod.getNewAutoPlaylistAction(myPod.TOOLBAR_ACTION));
        addAutoPlaylistButton.setFont(new java.awt.Font("Dialog", 1, 10));
        addAutoPlaylistButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/NewFilter24.gif")));
        addAutoPlaylistButton.setText(GuiUtils.getStringLocalized("dummy"));
        addAutoPlaylistButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        playlistToolBar.add(addAutoPlaylistButton);

        deletePlaylistButton.setAction(myPod.getDeletePlaylistAction(myPod.TOOLBAR_ACTION));
        deletePlaylistButton.setFont(new java.awt.Font("Dialog", 1, 10));
        deletePlaylistButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/DeleteFilter24.gif")));
        deletePlaylistButton.setText(GuiUtils.getStringLocalized("dummy"));
        deletePlaylistButton.setDefaultCapable(false);
        deletePlaylistButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        deletePlaylistButton.setRolloverEnabled(true);
        playlistToolBar.add(deletePlaylistButton);

        toolbarPanel.add(playlistToolBar);

        iPodToolBar.setRollover(true);
        synchronizeIPodButton.setAction(myPod.getSynchronizeIPodAction(myPod.TOOLBAR_ACTION));
        synchronizeIPodButton.setFont(new java.awt.Font("Dialog", 1, 10));
        synchronizeIPodButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/RefreshIPod24.gif")));
        synchronizeIPodButton.setText(GuiUtils.getStringLocalized("dummy"));
        synchronizeIPodButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        iPodToolBar.add(synchronizeIPodButton);

        wipeIPodButton.setAction(myPod.getWipeIPodAction(myPod.TOOLBAR_ACTION));
        wipeIPodButton.setFont(new java.awt.Font("Dialog", 1, 10));
        wipeIPodButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resource/DeleteIPod24.gif")));
        wipeIPodButton.setText(GuiUtils.getStringLocalized("dummy"));
        wipeIPodButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
        iPodToolBar.add(wipeIPodButton);

        toolbarPanel.add(iPodToolBar);

        getContentPane().add(toolbarPanel, java.awt.BorderLayout.NORTH);

        splitPane.setPreferredSize(new java.awt.Dimension(800, 600));
        playlistScrollPane.setMinimumSize(new java.awt.Dimension(150, 22));
        playlistScrollPane.setPreferredSize(new java.awt.Dimension(150, 150));
        playlistListView.setModel(myPod.getPlaylistListModel());
        playlistListView.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        playlistListView.setDragEnabled(true);
        playlistListView.setSelectedIndex(0);
        playlistListView.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
                public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                    playlistListViewValueChanged(evt);
                }
            });
        playlistListView.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mousePressed(java.awt.event.MouseEvent evt) {
                    playlistListViewMousePressed(evt);
                }

                public void mouseReleased(java.awt.event.MouseEvent evt) {
                    playlistListViewMouseReleased(evt);
                }
            });

        playlistScrollPane.setViewportView(playlistListView);

        splitPane.setLeftComponent(playlistScrollPane);

        viewContainer.setFont(new java.awt.Font("Dialog", 1, 10));
        fullListScrollPane.setName("fullListView");
        fullListScrollPane.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentShown(java.awt.event.ComponentEvent evt) {
                    fullListScrollPaneComponentShown(evt);
                }
            });

        clipsTableView.setModel(new de.axelwernicke.mypod.ClipsTableModel());
        clipsTableView.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        clipsTableView.setColumnModel(new de.axelwernicke.mypod.ClipsTableColumnModel());
        clipsTableView.setDragEnabled(true);
        clipsTableView.setGridColor(new java.awt.Color(204, 204, 204));
        clipsTableView.setName(GuiUtils.getStringLocalized("resource/language", "listView"));
        myPod.setClipsTableColumnListener(clipsTableView);
        clipsTableView.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mousePressed(java.awt.event.MouseEvent evt) {
                    clipsTableViewMousePressed(evt);
                }

                public void mouseReleased(java.awt.event.MouseEvent evt) {
                    clipsTableViewMouseReleased(evt);
                }
            });

        fullListScrollPane.setViewportView(clipsTableView);

        viewContainer.addTab(GuiUtils.getStringLocalized("resource/language", "listView"), fullListScrollPane);

        artistViewSplitPane.setName("artistView");
        artistViewSplitPane.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentShown(java.awt.event.ComponentEvent evt) {
                    artistViewSplitPaneComponentShown(evt);
                }
            });

        spreaderListView.setFont(new java.awt.Font("Dialog", 0, 12));
        spreaderListView.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        spreaderListView.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
                public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                    spreaderListViewValueChanged(evt);
                }
            });

        artistSpreaderScrollPane.setViewportView(spreaderListView);

        artistViewSplitPane.setLeftComponent(artistSpreaderScrollPane);

        artistViewSplitPane.setRightComponent(artistListScrollPane);

        viewContainer.addTab(GuiUtils.getStringLocalized("resource/language", "artistView"), artistViewSplitPane);

        albumViewSplitPane.setName("albumView");
        albumViewSplitPane.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentShown(java.awt.event.ComponentEvent evt) {
                    albumViewSplitPaneComponentShown(evt);
                }
            });

        albumViewSplitPane.setLeftComponent(albumSpreaderScrollPane);

        albumViewSplitPane.setRightComponent(albumListScrollPane);

        viewContainer.addTab(GuiUtils.getStringLocalized("resource/language", "albumView"), albumViewSplitPane);

        genreViewSplitPane.setName("genreView");
        genreViewSplitPane.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentShown(java.awt.event.ComponentEvent evt) {
                    genreViewSplitPaneComponentShown(evt);
                }
            });

        genreViewSplitPane.setLeftComponent(genreSpreaderScrollPane);

        genreViewSplitPane.setRightComponent(genreListScrollPane);

        viewContainer.addTab(GuiUtils.getStringLocalized("resource/language", "genreView"), genreViewSplitPane);

        splitPane.setRightComponent(viewContainer);

        getContentPane().add(splitPane, java.awt.BorderLayout.CENTER);

        statusLine.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 0, 1));

        statusLine.setAlignmentX(0.0F);
        statusLine.setAlignmentY(0.0F);
        statusLine.setFont(new java.awt.Font("Dialog", 0, 10));
        statusLine.setName("statusline");
        statusLine.setPreferredSize(new java.awt.Dimension(14, 20));
        clipsInfoLabel.setFont(new java.awt.Font("Dialog", 1, 10));
        clipsInfoLabel.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        clipsInfoLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        clipsInfoLabel.setBorder(new javax.swing.border.EtchedBorder());
        clipsInfoLabel.setMaximumSize(new java.awt.Dimension(640, 20));
        clipsInfoLabel.setMinimumSize(new java.awt.Dimension(100, 20));
        clipsInfoLabel.setPreferredSize(new java.awt.Dimension(250, 20));
        statusLine.add(clipsInfoLabel);

        dummyjPanel.setMinimumSize(new java.awt.Dimension(20, 10));
        dummyjPanel.setPreferredSize(new java.awt.Dimension(20, 10));
        statusLine.add(dummyjPanel);

        getContentPane().add(statusLine, java.awt.BorderLayout.SOUTH);

        menuBar.setFont(new java.awt.Font("Dialog", 1, 10));
        fileMenu.setMnemonic('f');
        fileMenu.setText(GuiUtils.getStringLocalized("resource/language", "file"));
        fileMenu.setName("fileMenu");
        scanMenuItem.setAction(myPod.getScanAction(myPod.MENU_ACTION));
        scanMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        scanMenuItem.setText(GuiUtils.getStringLocalized("ScanDiscForMedia..."));
        fileMenu.add(scanMenuItem);

        fileMenu.add(jSeparator2);

        preferencesMenuItem.setAction(myPod.getPreferencesAction(myPod.MENU_ACTION));
        preferencesMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        fileMenu.add(preferencesMenuItem);

        fileMenu.add(separator);

        exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        exitMenuItem.setAction(myPod.getExitAction());
        exitMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        playlistMenu.setText(GuiUtils.getStringLocalized("resource/language", "playlist"));
        playlistMenu.setName("playlistMenu");
        playlistMenu.addMenuListener(new javax.swing.event.MenuListener() {
                public void menuCanceled(javax.swing.event.MenuEvent evt) {
                }

                public void menuDeselected(javax.swing.event.MenuEvent evt) {
                }

                public void menuSelected(javax.swing.event.MenuEvent evt) {
                    playlistMenuMenuSelected(evt);
                }
            });

        playMenuItem.setAction(myPod.getPlayPlaylistAddAction(myPod.MENU_ACTION));
        playMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        playMenuItem.setName("playMenuItem");
        playlistMenu.add(playMenuItem);

        playAppendMenuItem.setAction(myPod.getPlayPlaylistAppendAction(myPod.MENU_ACTION));
        playAppendMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        playAppendMenuItem.setName("playAppendMenuItem");
        playlistMenu.add(playAppendMenuItem);

        playlistMenu.add(jSeparator12);

        newPlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        newPlaylistMenuItem.setAction(myPod.getNewPlaylistAction(myPod.MENU_ACTION));
        playlistMenu.add(newPlaylistMenuItem);

        newAutoPlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        newAutoPlaylistMenuItem.setAction(myPod.getNewAutoPlaylistAction(myPod.MENU_ACTION));
        playlistMenu.add(newAutoPlaylistMenuItem);

        renamePlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        renamePlaylistMenuItem.setAction(myPod.getRenamePlaylistAction(myPod.MENU_ACTION));
        playlistMenu.add(renamePlaylistMenuItem);

        deletePlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        deletePlaylistMenuItem.setAction(myPod.getDeletePlaylistAction(myPod.MENU_ACTION));
        playlistMenu.add(deletePlaylistMenuItem);

        playlistMenu.add(jSeparator31);

        importPlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        importPlaylistMenuItem.setAction(myPod.getImportPlaylistAction(myPod.MENU_ACTION));
        playlistMenu.add(importPlaylistMenuItem);

        exportPlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        exportPlaylistMenuItem.setAction(myPod.getExportPlaylistAction(myPod.MENU_ACTION));
        playlistMenu.add(exportPlaylistMenuItem);

        updateAutoplaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        updateAutoplaylistMenuItem.setAction(myPod.getUpdateAutoPlaylistAction(myPod.MENU_ACTION));
        playlistMenu.add(updateAutoplaylistMenuItem);

        playlistMenu.add(jSeparator111);

        propertyPlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        propertyPlaylistMenuItem.setAction(myPod.getPlaylistPropertyAction(myPod.MENU_ACTION));
        playlistMenu.add(propertyPlaylistMenuItem);

        menuBar.add(playlistMenu);

        clipMenu.setText(GuiUtils.getStringLocalized("resource/language", "clip"));
        clipMenu.setName("clipMenu");
        clipMenu.addMenuListener(new javax.swing.event.MenuListener() {
                public void menuCanceled(javax.swing.event.MenuEvent evt) {
                }

                public void menuDeselected(javax.swing.event.MenuEvent evt) {
                }

                public void menuSelected(javax.swing.event.MenuEvent evt) {
                    clipMenuMenuSelected(evt);
                }
            });

        playPopupItem2.setAction(myPod.getPlayClipsAddAction(myPod.POPUP_ACTION));
        playPopupItem2.setFont(new java.awt.Font("Dialog", 1, 10));
        clipMenu.add(playPopupItem2);

        playAppendPopupItem2.setAction(myPod.getPlayClipsAppendAction(myPod.POPUP_ACTION));
        playAppendPopupItem2.setFont(new java.awt.Font("Dialog", 1, 10));
        clipMenu.add(playAppendPopupItem2);

        clipMenu.add(jSeparator8);

        removeClipsPlaylistMenuItem.setAction(myPod.getRemoveClipsPlaylistAction(myPod.MENU_ACTION));
        removeClipsPlaylistMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        clipMenu.add(removeClipsPlaylistMenuItem);

        removeClipsMyPodMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        removeClipsMyPodMenuItem.setAction(myPod.getRemoveClipsMyPodAction(myPod.MENU_ACTION));
        clipMenu.add(removeClipsMyPodMenuItem);

        deleteClipsMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        deleteClipsMenuItem.setAction(myPod.getDeleteClipsAction(myPod.MENU_ACTION));
        clipMenu.add(deleteClipsMenuItem);

        clipMenu.add(jSeparator7);

        clipPropertiesMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        clipPropertiesMenuItem.setAction(myPod.getClipPropertiesAction(myPod.POPUP_ACTION));
        clipMenu.add(clipPropertiesMenuItem);

        menuBar.add(clipMenu);

        iPodMenu.setText(GuiUtils.getStringLocalized("resource/language", "ipod"));
        iPodMenu.setName("iPodMenu");
        synchronizeIPodMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        synchronizeIPodMenuItem.setAction(myPod.getSynchronizeIPodAction(myPod.MENU_ACTION));
        iPodMenu.add(synchronizeIPodMenuItem);

        wipeIPodMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        wipeIPodMenuItem.setText(GuiUtils.getStringLocalized("resource/language", "wipeIPod"));
        wipeIPodMenuItem.setAction(myPod.getWipeIPodAction(myPod.MENU_ACTION));
        iPodMenu.add(wipeIPodMenuItem);

        menuBar.add(iPodMenu);

        ToolsMenu.setText(GuiUtils.getStringLocalized("resource/language", "tools"));
        ToolsMenu.setName("ToolsMenu");
        removeMissingClipsMenuItem.setAction(myPod.getRemoveMissingClipsAction(myPod.MENU_ACTION));
        removeMissingClipsMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        ToolsMenu.add(removeMissingClipsMenuItem);

        relocateMissingClipsMenuItem.setAction(myPod.getRelocateMissingClipsAction(myPod.MENU_ACTION));
        relocateMissingClipsMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        ToolsMenu.add(relocateMissingClipsMenuItem);

        reorganizeClipsMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        reorganizeClipsMenuItem.setAction(myPod.getReorganizeClipsAction(myPod.MENU_ACTION));
        ToolsMenu.add(reorganizeClipsMenuItem);

        menuBar.add(ToolsMenu);

        helpMenu.setText(GuiUtils.getStringLocalized("resource/language", "help"));
        helpMenu.setName("helpMenu");
        helpMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        helpMenuItem.setAction(myPod.getHelpAction(myPod.MENU_ACTION));
        helpMenu.add(helpMenuItem);

        aboutMenuItem.setFont(new java.awt.Font("Dialog", 1, 10));
        aboutMenuItem.setText(GuiUtils.getStringLocalized("resource/language", "about..."));
        aboutMenuItem.setAction(myPod.getAboutAction(myPod.MENU_ACTION));
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setJMenuBar(menuBar);

        pack();
    } //GEN-END:initComponents

    /** Handle mouse pressed event for the clips table */
    private void clipsTableViewMousePressed(java.awt.event.MouseEvent evt) //GEN-FIRST:event_clipsTableViewMousePressed
     { //GEN-HEADEREND:event_clipsTableViewMousePressed
        if (evt.isPopupTrigger()) {
            showClipsPopupMenu(evt);
        }
    } //GEN-LAST:event_clipsTableViewMousePressed

    /** Handle mouse pressed event for the playlist list */
    private void playlistListViewMousePressed(java.awt.event.MouseEvent evt) //GEN-FIRST:event_playlistListViewMousePressed
     { //GEN-HEADEREND:event_playlistListViewMousePressed
        if (evt.isPopupTrigger()) {
            showPlaylistPopupMenu(evt);
        }
    } //GEN-LAST:event_playlistListViewMousePressed

    /** Handle the menu selected event for the clip menu.
     *        Enables / Disables clip menu items before menu is shown
     * @param evt
     */
    private void clipMenuMenuSelected(javax.swing.event.MenuEvent evt) //GEN-FIRST:event_clipMenuMenuSelected
     { //GEN-HEADEREND:event_clipMenuMenuSelected
        // we have to care only if the gui is not locked...
        if (!this.isLocked()) {
            boolean clipsSelected = ((clipsTableView == null) || clipsTableView.getSelectedClips().isEmpty()) ? false : true;
            setMenuLocked(this.clipMenu, !clipsSelected);
        }
    } //GEN-LAST:event_clipMenuMenuSelected

    /** Handle the menu selected event for the playlist menu.
     *        Enables / Disables playlist menu items before menu is shown
     *
     * @param evt
     */
    private void playlistMenuMenuSelected(javax.swing.event.MenuEvent evt) //GEN-FIRST:event_playlistMenuMenuSelected
     { //GEN-HEADEREND:event_playlistMenuMenuSelected
        // we have to care only if the gui is not locked...
        if (!this.isLocked()) {
            // check if any playlist is enabled
            int index = this.playlistListView.getSelectedIndex();

            if (index != -1) {
                Playlist playlist = myPod.getPlaylist(index);

                // enable (auto-)playlist related functions
                if (playlist.isAutoplaylist()) {
                    setLockedAutoPlaylistActions(false);
                    setLockedPlaylistActions(false);
                } else {
                    setLockedAutoPlaylistActions(true);
                    setLockedPlaylistActions(false);
                }
            }
        }
    } //GEN-LAST:event_playlistMenuMenuSelected

    /** Handles selection change event for clips table
     * @param evt
     */
    private void clipsListViewValueChanged(javax.swing.event.ListSelectionEvent evt) {
        // check if its not an intermediate event
        if (!evt.getValueIsAdjusting()) {
            GuiUtils.updateStatusLine(this);
        }
    }

    /** Handles selection changes of the playlist list
     *
     * @param evt
     */
    private void playlistListViewValueChanged(javax.swing.event.ListSelectionEvent evt) //GEN-FIRST:event_playlistListViewValueChanged
     { //GEN-HEADEREND:event_playlistListViewValueChanged
        // set curser to waitcurser
        Cursor oldCursor = getCursor();
        setCursor(new Cursor(Cursor.WAIT_CURSOR));

        // determine the selected items index - its a playlist index
        int index = this.playlistListView.getSelectedIndex();

        // check if the index is valid and its no intermediate event
        if ((index >= 0) && !evt.getValueIsAdjusting()) {
            // make sure the selection is visible
            this.playlistListView.scrollRectToVisible(this.playlistListView.getCellBounds(index, index));

            // determine playlist the user selected
            Playlist playlist = myPod.getPlaylist(index);

            // check which view is active
            String viewName = this.getCurrentViewName();

            // update models depending on the current view
            if (viewName.equals("fullListView")) {
                // set clips table model to new playlist
                myPod.updateClipsTableModel(playlist);
            } else if (viewName.equals("artistView")) {
                // set artist view to new playlist and clear clips table
                this.spreaderListView.setModel(myPod.getSpreaderListModel(ClipsTableUtils.Artist.ordinal(), index));
                myPod.updateClipsTableModel(new Playlist());
            } else if (viewName.equals("albumView")) {
                // set album view to new playlist and clear clips table
                this.spreaderListView.setModel(myPod.getSpreaderListModel(ClipsTableUtils.Album.ordinal(), index));
                myPod.updateClipsTableModel(new Playlist());
            } else if (viewName.equals("genreView")) {
                // set genre view to new playlist and clear clips table
                this.spreaderListView.setModel(myPod.getSpreaderListModel(ClipsTableUtils.Genre.ordinal(), index));
                myPod.updateClipsTableModel(new Playlist());
            }

            // update status line
            GuiUtils.updateStatusLine(this);
        }

        // reset cursor
        setCursor(oldCursor);
    } //GEN-LAST:event_playlistListViewValueChanged

    /** Handles selection changes of the spreader list view
     *
     * @param evt
     */
    private void spreaderListViewValueChanged(javax.swing.event.ListSelectionEvent evt) //GEN-FIRST:event_spreaderListViewValueChanged
     { //GEN-HEADEREND:event_spreaderListViewValueChanged
        // set curser to waitcurser
        Cursor oldCursor = getCursor();
        setCursor(new Cursor(Cursor.WAIT_CURSOR));

        // determine the selected items index - its a playlist index
        int index = this.spreaderListView.getSelectedIndex();

        // check if the index is valid and its no intermediate event
        if ((index >= 0) && !evt.getValueIsAdjusting()) {
            // make sure the selection is visible
            this.spreaderListView.scrollRectToVisible(this.spreaderListView.getCellBounds(index, index));

            // create new Autoplaylist and playlist filter
            AutoPlaylist autoplaylist = new AutoPlaylist();
            List<String> playlistFilter = new ArrayList<String>(1);
            playlistFilter.add(this.spreaderListView.getSelectedValue().toString());

            // check which view is active
            String viewName = this.getCurrentViewName();

            // update models depending on the current view
            if (viewName.equals("artistView")) {
                autoplaylist.setArtistFilterEnabled(true);
                autoplaylist.setArtistFilter(playlistFilter);
                myPod.getBackend().updateAutoplaylist(autoplaylist, ((Playlist) this.playlistListView.getSelectedValue()).getAllClips());
                myPod.updateClipsTableModel(autoplaylist);
            } else if (viewName.equals("albumView")) {
                // set rule for new autoplaylist
                autoplaylist.setAlbumFilterEnabled(true);
                autoplaylist.setAlbumFilter(playlistFilter);
                myPod.getBackend().updateAutoplaylist(autoplaylist, ((Playlist) this.playlistListView.getSelectedValue()).getAllClips());
                myPod.updateClipsTableModel(autoplaylist);
            } else if (viewName.equals("genreView")) {
                // set rule for new autoplaylist
                autoplaylist.setGenreFilterEnabled(true);
                autoplaylist.setGenreFilter(playlistFilter);
                myPod.getBackend().updateAutoplaylist(autoplaylist, ((Playlist) this.playlistListView.getSelectedValue()).getAllClips());
                myPod.updateClipsTableModel(autoplaylist);
            }

            // update status line
            GuiUtils.updateStatusLine(this);
        }

        // reset cursor
        setCursor(oldCursor);
    } //GEN-LAST:event_spreaderListViewValueChanged

    /** Handle the activation of the genre view
     * @param evt
     */
    private void genreViewSplitPaneComponentShown(java.awt.event.ComponentEvent evt) //GEN-FIRST:event_genreViewSplitPaneComponentShown
     { //GEN-HEADEREND:event_genreViewSplitPaneComponentShown
        // set curser to waitcurser
        Cursor oldCursor = getCursor();
        setCursor(new Cursor(Cursor.WAIT_CURSOR));

        try {
            // change model of spreader list and clips table
            myPod.updateClipsTableModel(new Playlist());
            this.spreaderListView.setModel(myPod.getSpreaderListModel(ClipsTableUtils.Genre.ordinal()));

            // change viewports
            this.genreSpreaderScrollPane.setViewportView(this.spreaderListView);
            this.genreListScrollPane.setViewportView(this.clipsTableView);

            // update status bar
            GuiUtils.updateStatusLine(this);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // set cursor back
        setCursor(oldCursor);
    } //GEN-LAST:event_genreViewSplitPaneComponentShown

    /** Handle the activation of the album view
     * @param evt
     */
    private void albumViewSplitPaneComponentShown(java.awt.event.ComponentEvent evt) //GEN-FIRST:event_albumViewSplitPaneComponentShown
     { //GEN-HEADEREND:event_albumViewSplitPaneComponentShown
        // set curser to waitcurser
        Cursor oldCursor = getCursor();
        setCursor(new Cursor(Cursor.WAIT_CURSOR));

        try {
            // change model of spreader list and clips table
            myPod.updateClipsTableModel(new Playlist());
            this.spreaderListView.setModel(myPod.getSpreaderListModel(ClipsTableUtils.Album.ordinal()));

            // change viewports
            this.albumSpreaderScrollPane.setViewportView(this.spreaderListView);
            this.albumListScrollPane.setViewportView(this.clipsTableView);

            // update status bar
            GuiUtils.updateStatusLine(this);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // set cursor back
        setCursor(oldCursor);
    } //GEN-LAST:event_albumViewSplitPaneComponentShown

    /** Handle the activation of the artist view
     */
    private void artistViewSplitPaneComponentShown(java.awt.event.ComponentEvent evt) //GEN-FIRST:event_artistViewSplitPaneComponentShown
     { //GEN-HEADEREND:event_artistViewSplitPaneComponentShown
        // set curser to waitcurser
        Cursor oldCursor = getCursor();
        setCursor(new Cursor(Cursor.WAIT_CURSOR));

        try {
            // change model of spreader list and clips table
            myPod.updateClipsTableModel(new Playlist());
            this.spreaderListView.setModel(myPod.getSpreaderListModel(ClipsTableUtils.Artist.ordinal()));

            // change viewports
            this.artistSpreaderScrollPane.setViewportView(this.spreaderListView);
            this.artistListScrollPane.setViewportView(this.clipsTableView);

            // update status bar
            GuiUtils.updateStatusLine(this);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // set cursor back
        setCursor(oldCursor);
    } //GEN-LAST:event_artistViewSplitPaneComponentShown

    /** Handle the activation of the full list view
     * @param evt
     */
    private void fullListScrollPaneComponentShown(java.awt.event.ComponentEvent evt) //GEN-FIRST:event_fullListScrollPaneComponentShown
     { //GEN-HEADEREND:event_fullListScrollPaneComponentShown
        // set curser to waitcurser
        Cursor oldCursor = getCursor();
        setCursor(new Cursor(Cursor.WAIT_CURSOR));

        try {
            // set clips table model & viewport
            myPod.updateClipsTableModel((Playlist) this.playlistListView.getSelectedValue());
            this.fullListScrollPane.setViewportView(this.clipsTableView);

            // update status bar
            GuiUtils.updateStatusLine(this);
        } catch (Exception e) {
            e.printStackTrace();
        }

        // set cursor back
        setCursor(oldCursor);
    } //GEN-LAST:event_fullListScrollPaneComponentShown

    /** Handle mouse click in table list view.
     *
     * @param evt
     */
    private void clipsTableViewMouseReleased(java.awt.event.MouseEvent evt) //GEN-FIRST:event_clipsTableViewMouseReleased
     { //GEN-HEADEREND:event_clipsTableViewMouseReleased
        if (evt.isPopupTrigger()) {
            // show context menu
            showClipsPopupMenu(evt);
        } else if (evt.getClickCount() == 2) {
            // TODO: make this customizable via preferences - play doubleclicked clips
            myPod.getPlayClipsAddAction(-1).actionPerformed(null);
        }
    } //GEN-LAST:event_clipsTableViewMouseReleased

    /** Handle mouse click in table list view.
     *
     * @param evt mouse event
     */
    private void playlistListViewMouseReleased(java.awt.event.MouseEvent evt) //GEN-FIRST:event_playlistListViewMouseReleased
     { //GEN-HEADEREND:event_playlistListViewMouseReleased
        if (evt.isPopupTrigger()) {
            this.showPlaylistPopupMenu(evt);
        }
    } //GEN-LAST:event_playlistListViewMouseReleased

    /** Handles window closing event
     * @param evt window event
     */
    private void formWindowClosing(java.awt.event.WindowEvent evt) //GEN-FIRST:event_formWindowClosing
     { //GEN-HEADEREND:event_formWindowClosing
        // check if gui is locked
        if (!this.isLocked()) {
            myPod.getExitAction().actionPerformed(null);
        }
    } //GEN-LAST:event_formWindowClosing

    /** Gets the full list view.
     * Since all views are sharing one listView object, there will be always the same object returned...
     *
     * @return full list view
     */
    public ListView getClipsTableView() {
        return this.clipsTableView;
    }

    /** gets the name of the current view
     *
     * @return name of the current clips table view
     */
    public String getCurrentViewName() {
        String viewName = "";
        try {
            viewName = this.viewContainer.getSelectedComponent().getName();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return viewName;
    }

    /** Sets GUI Preferences like main window bounds and divider positions
     *
     * @param prefs myPod preferences to get gui properties from
     */
    public void setPreferences(Preferences prefs) {
        this.setBounds(prefs.getMainFramePosition());
        this.splitPane.setDividerLocation(prefs.getDividerMainPosition());
        this.artistViewSplitPane.setDividerSize(4);
        this.artistViewSplitPane.setDividerLocation(prefs.getDividerArtistViewPosition());
        this.artistViewSplitPane.setDividerSize(2);
        this.albumViewSplitPane.setDividerLocation(prefs.getDividerAlbumViewPosition());
        this.albumViewSplitPane.setDividerSize(2);
        this.genreViewSplitPane.setDividerLocation(prefs.getDividerGenreViewPosition());
        this.genreViewSplitPane.setDividerSize(2);
    }

    /** Store GUI Preferences like main window bounds and divider positions
     *
     * @param prefs myPod preferences object where to store gui properties
     * @return prefs object containing gui properties
     */
    public Preferences getPreferences(Preferences prefs) {
        prefs.setMainFramePosition(this.getBounds());
        prefs.setDividerMainPosition(this.splitPane.getDividerLocation());
        prefs.setDividerArtistViewPosition(this.artistViewSplitPane.getDividerLocation());
        prefs.setDividerAlbumViewPosition(this.albumViewSplitPane.getDividerLocation());
        prefs.setDividerGenreViewPosition(this.genreViewSplitPane.getDividerLocation());

        return prefs;
    }

    /** Getter for property playlistListView.
     * @return Value of property playlistListView.
     */
    public de.axelwernicke.mypod.gui.PlaylistListView getPlaylistListView() {
        return playlistListView;
    }

    /** Shows the popup (context) menu for a clip
     * @param evt mouse event that triggered the popup
     */
    private void showClipsPopupMenu(java.awt.event.MouseEvent evt) {
        // make sure that the gui is not locked
        if (!this.isLocked()) {
            // select row under the mouse pointer if it is not in a selection yet
            int row = ((ListView) evt.getComponent()).rowAtPoint(evt.getPoint());
            if (!((ListView) evt.getComponent()).isRowSelected(row)) {
                ((ListView) evt.getComponent()).setRowSelectionInterval(row, row);
            }

            // make sure the clips actions are enabled
            this.setMenuLocked(this.clipMenu, false);

            // recreate playlist submenu items
            addPlaylistMenu.removeAll();
            List<Component> playlistMenuItems = myPod.getPlaylistMenuItems();
            int playlistCount = playlistMenuItems.size();
            for (int i = 0; i < playlistCount; i++) {
                addPlaylistMenu.add(playlistMenuItems.get(i));
            }
            playlistMenuItems = null;

            // show popup
            clipPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
        }
    }

    /** Shows the popup (context) menu for a playlist
     * @param evt mouse event that triggered the popup
     */
    private void showPlaylistPopupMenu(java.awt.event.MouseEvent evt) {
        // show only if gui is not locked
        if (!this.isLocked()) {
            // get index under mouse pointer and check if the user clicked within a cell
            int index = ((PlaylistListView) evt.getComponent()).locationToIndex(evt.getPoint());
            if (index >= 0) {
                // select cell and get playlist
                this.playlistListView.setSelectedIndex(index);
                Playlist playlist = myPod.getPlaylist(index);

                // enable (auto-)playlist related functions
                if (playlist.isAutoplaylist()) {
                    setLockedAutoPlaylistActions(false);
                    setLockedPlaylistActions(false);
                } else {
                    setLockedAutoPlaylistActions(true);
                    setLockedPlaylistActions(false);
                }

                // set iPod sync checkbox
                this.syncIPodCheckBoxMenuItem.setSelected(playlist.isIPodSync());
            } else {
                setLockedAutoPlaylistActions(true);
                setLockedPlaylistActions(true);
            }

            // show popup menu
            playlistPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
        }
    }

    /** (un-)locks a menu by (dis-)abling menu item actions.
     */
    private void setMenuLocked(JMenu menu, boolean lock) {
        if (menu != null) {
            javax.swing.JMenuItem item;
            int itemCnt = menu.getItemCount();
            for (int pos = 0; pos < itemCnt; pos++) {
                item = menu.getItem(pos);
                if ((item != null) && (item.getAction() != null)) {
                    item.getAction().setEnabled(!lock);
                }
            }
        }
    }

    /** Getter for property locked.
     * @return Value of property locked.
     *
     */
    public boolean isLocked() {
        return locked;
    }

    /** Setter for property locked.
     * @param locked New value of property locked.
     */
    public void setLocked(boolean lock) {
        // set cursor
        this.setCursor(lock ? new Cursor(Cursor.WAIT_CURSOR) : new Cursor(Cursor.DEFAULT_CURSOR));

        // lock menus
        int menuCount = this.menuBar.getMenuCount();
        for (int m = 0; m < menuCount; m++) {
            setMenuLocked(this.menuBar.getMenu(m), lock);
        }

//		// lock content panes
//		this.playlistListView.setEnabled(!lock);
//		this.viewContainer.setEnabled(!lock);
//		this.spreaderListView.setEnabled(!lock);
//		this.clipsTableView.setEnabled(!lock);
        // remember the lock
        this.locked = lock;
    }

    private void setLockedPlaylistActions(boolean lock) {
        this.renamePlaylistPopupItem.getAction().setEnabled(!lock);
        this.deletePlaylistPopupItem.getAction().setEnabled(!lock);
        this.playPopupItem.getAction().setEnabled(!lock);
        this.playAppendPopupItem.getAction().setEnabled(!lock);
        this.propertyPlaylistPopupItem.getAction().setEnabled(!lock);

        this.playPopupItem.getAction().setEnabled(!lock && myPod.getBackend().getPreferences().isAddEnabled());
        this.playAppendPopupItem.getAction().setEnabled(!lock && myPod.getBackend().getPreferences().isAppendEnabled());
    }

    private void setLockedAutoPlaylistActions(boolean lock) {
        // check for an autoplaylist
        this.updateAutoplaylistPpupItem.getAction().setEnabled(!lock);
    }

    /** Sets the clip info text in the status line */
    void setClipsInfo(String text) {
        this.clipsInfoLabel.setText(text);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu ToolsMenu;
    private javax.swing.JMenuItem aboutMenuItem;
    private javax.swing.JButton addAutoPlaylistButton;
    private javax.swing.JButton addPlaylistButton;
    private javax.swing.JMenu addPlaylistMenu;
    private javax.swing.JScrollPane albumListScrollPane;
    private javax.swing.JScrollPane albumSpreaderScrollPane;
    private javax.swing.JSplitPane albumViewSplitPane;
    private javax.swing.JScrollPane artistListScrollPane;
    private javax.swing.JScrollPane artistSpreaderScrollPane;
    private javax.swing.JSplitPane artistViewSplitPane;
    private javax.swing.JMenu clipMenu;
    private javax.swing.JPopupMenu clipPopupMenu;
    private javax.swing.JMenuItem clipPropertiesMenuItem;
    private javax.swing.JMenuItem clipPropertiesPopupItem;
    public javax.swing.JLabel clipsInfoLabel;
    private de.axelwernicke.mypod.gui.ListView clipsTableView;
    private javax.swing.JMenuItem deleteClipsMenuItem;
    private javax.swing.JButton deletePlaylistButton;
    private javax.swing.JMenuItem deletePlaylistMenuItem;
    private javax.swing.JMenuItem deletePlaylistPopupItem;
    private javax.swing.JMenuItem deletePopupItem;
    private javax.swing.JPanel dummyjPanel;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenuItem exportPlaylistMenuItem;
    private javax.swing.JMenu fileMenu;
    private javax.swing.JScrollPane fullListScrollPane;
    private javax.swing.JScrollPane genreListScrollPane;
    private javax.swing.JScrollPane genreSpreaderScrollPane;
    private javax.swing.JSplitPane genreViewSplitPane;
    private javax.swing.JMenu helpMenu;
    private javax.swing.JMenuItem helpMenuItem;
    private javax.swing.JMenu iPodMenu;
    private javax.swing.JToolBar iPodToolBar;
    private javax.swing.JMenuItem importPlaylistMenuItem;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator11;
    private javax.swing.JSeparator jSeparator111;
    private javax.swing.JSeparator jSeparator12;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator31;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JToolBar myPodToolBar;
    private javax.swing.JMenuItem newAutoPlaylistMenuItem;
    private javax.swing.JMenuItem newPlaylistMenuItem;
    private javax.swing.JMenuItem playAppendMenuItem;
    private javax.swing.JMenuItem playAppendPopupItem;
    private javax.swing.JMenuItem playAppendPopupItem1;
    private javax.swing.JMenuItem playAppendPopupItem2;
    private javax.swing.JMenuItem playMenuItem;
    private javax.swing.JMenuItem playPopupItem;
    private javax.swing.JMenuItem playPopupItem1;
    private javax.swing.JMenuItem playPopupItem2;
    private de.axelwernicke.mypod.gui.PlaylistListView playlistListView;
    private javax.swing.JMenu playlistMenu;
    private javax.swing.JPopupMenu playlistPopupMenu;
    private javax.swing.JScrollPane playlistScrollPane;
    private javax.swing.JToolBar playlistToolBar;
    private javax.swing.JButton preferencesButton;
    private javax.swing.JMenuItem preferencesMenuItem;
    private javax.swing.JMenuItem propertyPlaylistMenuItem;
    private javax.swing.JMenuItem propertyPlaylistPopupItem;
    private javax.swing.JMenuItem relocateMissingClipsMenuItem;
    private javax.swing.JMenuItem removeClipsMyPodMenuItem;
    private javax.swing.JMenuItem removeClipsPlaylistMenuItem;
    private javax.swing.JMenuItem removeFromMyPodPopupItem;
    private javax.swing.JMenuItem removeFromPlaylsitPopupItem;
    private javax.swing.JMenuItem removeMissingClipsMenuItem;
    private javax.swing.JMenuItem renamePlaylistMenuItem;
    private javax.swing.JMenuItem renamePlaylistPopupItem;
    private javax.swing.JMenuItem reorganizeClipsMenuItem;
    private javax.swing.JButton scanButton;
    private javax.swing.JMenuItem scanMenuItem;
    private javax.swing.JSeparator separator;
    private javax.swing.JSplitPane splitPane;
    private javax.swing.JList spreaderListView;
    private javax.swing.JPanel statusLine;
    private javax.swing.JCheckBoxMenuItem syncIPodCheckBoxMenuItem;
    private javax.swing.JButton synchronizeIPodButton;
    private javax.swing.JMenuItem synchronizeIPodMenuItem;
    private javax.swing.JPanel toolbarPanel;
    private javax.swing.JMenuItem updateAutoplaylistMenuItem;
    private javax.swing.JMenuItem updateAutoplaylistPpupItem;
    private javax.swing.JTabbedPane viewContainer;
    private javax.swing.JButton wipeIPodButton;
    private javax.swing.JMenuItem wipeIPodMenuItem;

    // End of variables declaration//GEN-END:variables
}
